"use cilent";
import { addQuestionUsingPost } from "@/api/questionController";
import { ProColumns, ProTable } from "@ant-design/pro-components";
import { message, Modal } from "antd";
import React, { useState } from "react";

interface Props {
  isModalOpen: boolean;
  columns?: ProColumns<API.Question>[];
  onSubmit?: () => void;
  onCancel?: () => void;
}
/**
 * 添加节点
 * @returns
 */
const handleAdd = async (values: API.QuestionAddRequest) => {
  await addQuestionUsingPost(values);
};
/**
 * 创建弹窗
 * @returns
 */
const CreateModal: React.FC<Props> = (props: Props) => {
  const { isModalOpen, columns, onSubmit, onCancel } = props;
  const [messageApi, contextHolder] = message.useMessage();

  return (
    <>
      {contextHolder}
      <Modal
        title="新增用户"
        closable={{ "aria-label": "Custom Close Button" }}
        open={isModalOpen}
        onCancel={() => onCancel?.()}
        centered={true}
        footer={null}
      >
        <ProTable
          type="form"
          columns={columns}
          onSubmit={async (values: API.QuestionAddRequest) => {
            messageApi.open({
              content: "添加中...",
            });
              await addQuestionUsingPost(values);
              messageApi.destroy();
              messageApi.success("添加成功");
              onSubmit?.();
          }}
        />
      </Modal>
    </>
  );
};
export default CreateModal;
